<?php
/**
 *    Copyright 2010 Show Framework(www.showframework.cn)
 *    Licensed under the Apache License, Version 2.0 (the "License");
 *    you may not use this file except in compliance with the License.
 *    You may obtain a copy of the License at
 * 
 *        http://www.apache.org/licenses/LICENSE-2.0
 * 
 *    Unless required by applicable law or agreed to in writing, software
 *    distributed under the License is distributed on an "AS IS" BASIS,
 *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *    See the License for the specific language governing permissions and
 *    limitations under the License.
 */

/**
 * 去除 $_GET, $_POST, $_COOKIE 的slashes
 * (自动检测magic_quotes_gpc的状态 不会造成不必要的清理)
 * 
 * @package Show_Filter
 * @name Show_Filter_Gpc
 * @author show
 * @since v0.6
 */
class Show_Filter_Gpc implements Show_Filter_Interface
{
    /**
     * 过滤
     *
     * @param mixed $value
     * @return mixed
     */
    public function filter($value = null)
    {
        if (get_magic_quotes_gpc() == 1) {
            if (!empty($_GET)) {
                array_walk_recursive($_GET, 'Show_Filter_Gpc::_stripslashes');
            }
            if (!empty($_POST)) {
                array_walk_recursive($_POST, 'Show_Filter_Gpc::_stripslashes');
            }
            if (!empty($_COOKIE)) {
                array_walk_recursive($_COOKIE, 'Show_Filter_Gpc::_stripslashes');
            }
        }
        return $value;
    }
    
    /**
     * 去除转义
     *
     * @param string $item
     * @param string $key
     * @return void
     */
    public static function _stripslashes(&$item, $key)
    {
        $item = stripslashes($item);
    }
}
?>